import { fileURLToPath, URL } from 'node:url'
import mpaPlugin from 'vite-plugin-mpa-plus'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import { resolve } from 'node:path'

const pages = [
  {
    entry: resolve(__dirname, './src/pages/second/index.html'),
    filename: resolve(__dirname, 'src/pages/second/index.html'),
    template: resolve(__dirname, './src/pages/second/index.html'),
    inject: {
      data: {
        title: 'mpa'
      }
    }
  }
];

const rewrites = [
  {
    from: /\/second/,
    to: '/second/index.html',
  }
]

// https://vite.dev/config/
export default defineConfig({
  root: resolve(__dirname, 'src/pages'),
  base: '/',
  plugins: [
    vue(),
    vueDevTools(),
    mpaPlugin({
      pages,
      historyApiFallback: {
        rewrites
      }
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  // build: {
  //   rollupOptions: {
  //     input: {
  //       main: resolve(__dirname, 'index.html'),
  //       second: resolve(__dirname, 'src/views/second/index.html')
  //     }
  //   }
  // }
})
